<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@page import="org.paradise.dms.pojo.SystemUserTask"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	SystemUserTask updatedTask = (SystemUserTask) request
			.getAttribute("updatedTask");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title></title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/common.css" type="text/css" />

		<s:head />
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/interface/dWRSystemUserAction.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type="text/javascript">
			//查询所有的用户组
			function getAllGroup(value){
				dWRSystemUserAction.findAllGroup(value,findAllGroupCallback);
			}
			var findAllGroupCallback = function findAllGroupCallbackFunc(groupList){
				  	var groupInfo =groupList;
					var s = $("systemusergroupid");
					 	DWRUtil.removeAllOptions(s);  
						s.options[0] = new Option("请选择用户组",'0');
					for ( var i = 1; i < groupList.length+1; i++) {
						var opt = new Option(groupList[i-1].systemusergroupname,
								groupList[i-1].systemusergroupid);
						s.options[i] = opt;
						//在所有的可见用户组中找到所要的用户组
						if("<%=updatedTask.getTaskacceptergroupid()%>" == groupList[i-1].systemusergroupid){
							s.options[i].selected = "selected";
						}
					}
					
					
			}
			
			//找到所有用户组权限值低于自己的用户.如果这里的用户很多,将影响性能,后期可能考虑去除此功能
			function getAllUserBebindValue(systemusergroupid,systemusergroupvalue){
				dWRSystemUserAction.findAllUserBehindValue(systemusergroupid,systemusergroupvalue,findAllUserBehindValueCallback);
			}
			var findAllUserBehindValueCallback = function findAllUserBehindValueCallbackFunc(systemUserList){
			  		var userInfo =systemUserList;
					var s = $("systemusertaskaccepter");
					DWRUtil.removeAllOptions(s);  
						s.options[0] = new Option("请选择用户",'0');
					for ( var i = 1; i < systemUserList.length+1; i++) {
						var opt = new Option(systemUserList[i-1].systemusername,
								systemUserList[i-1].systemusergroupid+"_"+systemUserList[i-1].systemuserid);
						s.options[i] = opt;
						//在所有的可见用户id中找到需要的用户id
						if("<%=updatedTask.getSystemusertaskaccepterid()%>" == systemUserList[i-1].systemuserid){
							s.options[i].selected = "selected";
						}
					}
			}
			//选择用户时,用户组联动
			function getGroupByUser(obj){
				var s =  obj.options[obj.selectedIndex].value
				for(var a=0;a<${'systemusergroupid'}.options.length;a++){
					if(${'systemusergroupid'}.options[a].value == s.substr(0,s.indexOf("_"))){
						${'systemusergroupid'}.options[a].selected = "selected";
					};
				}
			
			}
			//选择用户组时,用户联动
			function getUserByGroup(obj){
				dWRSystemUserAction.findUserByGroup(obj.options[obj.selectedIndex].value,findUserByGroupCallback);
				
			}
			var findUserByGroupCallback = function findUserByGroupCallbackFunc(systemUserList){
					if(systemUserList == null){
						systemUserList = "";
					}
					var s = $("systemusertaskaccepter");
					DWRUtil.removeAllOptions(s);  
						s.options[0] = new Option("请选择用户",'0');
					for ( var i = 1; i < systemUserList.length+1; i++) {
						var opt = new Option(systemUserList[i-1].systemusername,
								systemUserList[i-1].systemusergroupid+"_"+systemUserList[i-1].systemuserid);
						s.options[i] = opt;
					}
					
			}
			function submitForm(){
				var  sa = $('systemusertaskaccepter').options[$('systemusertaskaccepter').selectedIndex];
				$('accepterid').value = sa.value.substr(sa.value.indexOf("_")+1);
				$('accepter').value = sa.text;
				//alert($('accepter').value);
				//alert($('accepterid').value);
				$('taskForm').submit();
			}
			function setSearchedValue(){
				$("systemusertasktitle").value = "<%=updatedTask.getSystemusertasktitle()%>";
				dojo.widget.byId("systemusertaskduetime").setValue("<%=updatedTask.getSystemusertaskduetime()%>".substr(0,10));
				$("systemusetaskcontent").value = "<%=updatedTask.getSystemusetaskcontent()%>";
				$("systemusertaskmisc").value = "<%=updatedTask.getSystemusertaskmisc()%>";
				
			}
		
		
		
		</script>
	</head>

	<body
		onload="getAllGroup(3);getAllUserBebindValue(1,3);setSearchedValue()">
		<div id="page_container">
			<div id="page_nav">
				<%@include file="banner.jsp"%>
			</div>
			<s:form action="systemusergrouptaskallocation/updateTask.action"
				method="post" theme="simple" id="taskForm">
				<table class="table_common">
					<input type="hidden" value="<%=updatedTask.getSystemusertaskid()%>"
						name="systemusertaskid" />
					<input type="hidden"
						value="<%=updatedTask.getSystemusertaskassigner()%>"
						name="systemusertask.systemusertaskassigner" />
					<input type="hidden"
						value="<%=updatedTask.getSystemusertaskassignerid()%>"
						name="systemusertask.systemusertaskassignerid" />
					<tr>
						<td>
							任务名称：
						</td>
						<td>
							<s:textfield name='systemusertask.systemusertasktitle'
								id='systemusertasktitle' value="" />
						</td>
					</tr>
					<tr>
						<td>
							任务接受者:
						</td>
						<td>
							<select name='systemusertask.taskacceptergroupid'
								id='systemusergroupid' onchange="getUserByGroup(this)">
								<option 　value='1'>
									group1
								</option>
								<option value='2'>
									group2
								</option>
							</select>
							<input type="hidden" name='systemusertask.systemusertaskaccepter'
								id='accepter' />
							<input type="hidden"
								name='systemusertask.systemusertaskaccepterid' id='accepterid' />
							<select name='accepterid' id='systemusertaskaccepter'
								onchange="getGroupByUser(this)">
								<option 　value='1'>
									aaa
								</option>
								<option value='2'>
									bbb
								</option>
							</select>
						</td>
						<td>
					</tr>
					<tr>
						<td>
							任务到期时间：
						</td>
						<td>
							<s:datetimepicker name='systemusertask.systemusertaskduetime'
								id='systemusertaskduetime' label="Format (yyyy-MM-dd)"
								displayFormat="yyyy-MM-dd" />

						</td>
					</tr>
					<tr>
						<td>
							任务内容：
						</td>
						<td>
							<s:textarea name='systemusertask.systemusetaskcontent' cols="30"
								rows="8" id='systemusetaskcontent' value="" />

						</td>
					</tr>


					<tr>
						<td>
							任务备注：
						</td>
						<td>
							<s:textarea name='systemusertask.systemusertaskmisc' cols="30"
								rows="8" id='systemusertaskmisc' value="" />
						</td>
					<tr>
						<td>
							<input type="button" value="提交修改" onclick="submitForm()">
						</td>
					</tr>
				</table>
			</s:form>
		</div>
	</body>
</html>
